<?php
	require_once "header.php";
	
	session_start();
	
	
	$action = 'pro';
	
	$errorType = -1;
	
	
	if(isset($_POST['btn_ok'])  && isset ($_POST['hUserAction']) )
	{
		require_once "trackingModify.php";
	
		$action = $_POST['hUserAction'];
		
		if($action == "pas")
		{
			
			$cFilter = new CFilter;
		
			$cUsers  = new CUsers;
		
			$id = $_SESSION['idUser'];
			$oldPass  = $cFilter -> filter ( $_POST['tf_curpass']);
			$newPass = $cFilter -> filter ( $_POST['tf_newpassword']);
			$confirmPass = $cFilter -> filter ( $_POST['tf_newretypepassword']);
			
			if($newPass != $confirmPass)
			{
				$errorType = 0 ; 
				return ;
			}
			
			
			if($cUsers -> CUsersCheckPass($id, $_SESSION['username'],md5($oldPass)) == false)
			{
				
				$errorType =1;
				return ;
			}
			
			if($errorType == -1)
			{
				
				$isSuccess = $cUsers -> CUsersUpdatePass ($id, md5($newPass));
				
				if($isSuccess ==-1 || $isSuccess ==0){
					echo '<script language="javascript">window.location.href="main.php?jmp=note&to='."'"."addArticles_2"."'".'"</script>';  
				}
				else{
						if($isSuccess !=0){
							echo '<script language="javascript">window.location.href="main.php?jmp=note&to='."'"."addArticles_1"."'".'"</script>'; 			
						}		
				}
				
			}		

		}
		else
		{
			if($action == "pro")
			{
				$isSuccess = 0 ; 
			
				$cFilter = new CFilter;
		
				$cUsers  = new CUsers;
			
				$id = $_SESSION['idUser'];
				
				
				$lastname = $cFilter -> filter ($_POST['tf_lastname']);
				$firstname = $cFilter ->filter ($_POST['tf_firstname']);
				$gender = $_POST['rdbtn_gender'];
				$cellphone = $cFilter -> filter ( $_POST['tf_cellphone'] );
				$birthday = $cFilter -> filter ( $_POST['tf_birthday'] );
				$address = $_POST['tf_address'];
				
				
				
				$isSuccess = $cUsers -> CUsersUpdate ($id,$lastname,$firstname,$gender,$birthday,$cellphone,$address);
				
				
				if($isSuccess ==-1 || $isSuccess ==0){
					echo '<script language="javascript">window.location.href="main.php?jmp=note&to='."'"."addArticles_2"."'".'"</script>';  
				}
				else{
						if($isSuccess !=0){
							echo '<script language="javascript">window.location.href="main.php?jmp=note&to='."'"."addArticles_1"."'".'"</script>'; 			
						}		
				}
				
				
			}
			else
			{
				//echo "out ra process roi hihih";
						echo '<script language="javascript">window.location.href="main.php?jmp=profile&to=idb'.$action.'"</script>';  	
			}
			
		}
		
		
		
		
	}
	else
	{
		echo '<script language="javascript">window.location.href="main.php?jmp=profile&to=idb'.$action.'"</script>';  	

	}
	
	
	
	
	
	
	
	
	
	
	
	
	


?>